package com.itheima.a10threadsafe2;

public class MyRunnable  implements Runnable{
    int ticket=0;

    @Override
    public void run() {
       //1.循环
        while(true){
            //锁对象
                if (extracted()) break;

        }
    }

    private synchronized boolean extracted() {
        if(ticket<100){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            ticket++;
            System.out.println(Thread.currentThread().getName()+"在卖第"+ticket+"张票");
        }else{
            return true;
        }
        return false;
    }
}
